package com.hl.sfzy.exception;

import com.hl.sfzy.constant.Result;
import com.hl.sfzy.constant.SystemCode;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @program: sfzy
 * @ClassName ExceptionController
 * @description:
 * @author: lyp
 * @create: 2024-07-12 14:22
 * @Version 1.0
 **/
/*
* 全局异常处理器
* */
@ControllerAdvice
@ResponseBody
public class ExceptionController {
    //ExecptionHandler用于设置所标识方法处理的异常
    @ExceptionHandler(AppException.class)
    public Result handleException(AppException e){
        if(e.getMessage().equals("402")){
            return Result.error(SystemCode.USERNAME_ERROR.getCode(),SystemCode.USERNAME_ERROR.getMessage(),null);
        }else{
            return Result.error();
        }
    }
}

